﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BirdPlayer : MonoBehaviour {
	Rigidbody2D rigid2D;
	Animator animator;
	public float upForce;
	public bool isAlive = true;

	// Use this for initialization
	void Start () {
		rigid2D = GetComponent<Rigidbody2D> ();
		animator = GetComponent<Animator> ();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void Fly() {
		animator.SetTrigger ("Fly");
		rigid2D.velocity = Vector2.zero; // 先清空之前的力
		rigid2D.AddForce (new Vector2 (0, upForce));
	}

	public void Die() {
		isAlive = false;
		animator.SetTrigger ("Die");
		rigid2D.velocity = Vector2.zero;
		GameMode.instance.GameOver ();
	}

	public void OnCollisionEnter2D(Collision2D other) {
		Die ();
	}
		

}
